/*     */ package com.bj58.analysis.track.format;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ import org.apache.hadoop.conf.Configuration;
/*     */ import org.apache.hadoop.fs.FSDataInputStream;
/*     */ import org.apache.hadoop.fs.FileSystem;
/*     */ import org.apache.hadoop.fs.Path;
/*     */ import org.apache.hadoop.io.LongWritable;
/*     */ import org.apache.hadoop.io.Text;
/*     */ import org.apache.hadoop.io.compress.CompressionCodec;
/*     */ import org.apache.hadoop.io.compress.CompressionCodecFactory;
/*     */ import org.apache.hadoop.mapreduce.InputSplit;
/*     */ import org.apache.hadoop.mapreduce.RecordReader;
/*     */ import org.apache.hadoop.mapreduce.TaskAttemptContext;
/*     */ import org.apache.hadoop.mapreduce.lib.input.FileSplit;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ /**
/*     */  * @deprecated
/*     */  */
/*     */ public class TrackRecordReader
/*     */   extends RecordReader<LongWritable, Text>
/*     */ {
/*  29 */   private static final Log LOG = LogFactory.getLog(TrackRecordReader.class);
/*     */   
/*  31 */   public TrackRecordReader() { this.compressionCodecs = null;
/*     */     
/*     */ 
/*     */ 
/*  35 */     this.key = null;
/*  36 */     this.value = null;
/*     */     
/*     */ 
/*  39 */     this.separator = "end\n".getBytes();
/*     */   }
/*     */   
/*     */   private CompressionCodecFactory compressionCodecs;
/*     */   public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException {
/*  44 */     FileSplit split = (FileSplit)genericSplit;
/*  45 */     Configuration job = context.getConfiguration();
/*  46 */     this.maxLineLength = job.getInt("mapred.linerecordreader.maxlength", Integer.MAX_VALUE);
/*  47 */     this.start = split.getStart();
/*  48 */     this.end = (this.start + split.getLength());
/*  49 */     Path file = split.getPath();
/*  50 */     this.compressionCodecs = new CompressionCodecFactory(job);
/*  51 */     CompressionCodec codec = this.compressionCodecs.getCodec(file);
/*     */     
/*  53 */     FileSystem fs = file.getFileSystem(job);
/*  54 */     FSDataInputStream fileIn = fs.open(split.getPath());
/*  55 */     boolean skipFirstLine = false;
/*  56 */     if (codec != null) {
/*  57 */       this.in = new NewLineReader(codec.createInputStream(fileIn), job);
/*  58 */       this.end = Long.MAX_VALUE;
/*     */     } else {
/*  60 */       if (this.start != 0L) {
/*  61 */         skipFirstLine = true;
/*  62 */         this.start -= this.separator.length;
/*     */         
/*  64 */         fileIn.seek(this.start);
/*     */       }
/*  66 */       this.in = new NewLineReader(fileIn, job);
/*     */     }
/*  68 */     if (skipFirstLine) {
/*  69 */       this.start += this.in.readLine(new Text(), 0, (int)Math.min(2147483647L, this.end - this.start));
/*     */     }
/*  71 */     this.pos = this.start;
/*     */   }
/*     */   
/*     */   public boolean nextKeyValue() throws IOException {
/*  75 */     if (this.key == null) {
/*  76 */       this.key = new LongWritable();
/*     */     }
/*  78 */     this.key.set(this.pos);
/*  79 */     if (this.value == null) {
/*  80 */       this.value = new Text();
/*     */     }
/*  82 */     int newSize = 0;
/*  83 */     while (this.pos < this.end) {
/*  84 */       newSize = this.in.readLine(this.value, this.maxLineLength, Math.max((int)Math.min(2147483647L, this.end - this.pos), this.maxLineLength));
/*     */       
/*  86 */       if (newSize == 0) {
/*     */         break;
/*     */       }
/*  89 */       this.pos += newSize;
/*  90 */       if (newSize < this.maxLineLength) {
/*     */         break;
/*     */       }
/*     */       
/*  94 */       LOG.info("Skipped line of size " + newSize + " at pos " + (this.pos - newSize));
/*     */     }
/*  96 */     if (newSize == 0) {
/*  97 */       this.key = null;
/*  98 */       this.value = null;
/*  99 */       return false;
/*     */     }
/* 101 */     return true;
/*     */   }
/*     */   
/*     */   private long start;
/*     */   public LongWritable getCurrentKey()
/*     */   {
/* 107 */     return this.key;
/*     */   }
/*     */   
/*     */   private long pos;
/*     */   private long end;
/* 112 */   public Text getCurrentValue() { return this.value; }
/*     */   
/*     */   private NewLineReader in;
/*     */   private int maxLineLength;
/*     */   private LongWritable key;
/*     */   private Text value;
/*     */   private byte[] separator;
/* 119 */   public float getProgress() { if (this.start == this.end) {
/* 120 */       return 0.0F;
/*     */     }
/* 122 */     return Math.min(1.0F, (float)(this.pos - this.start) / (float)(this.end - this.start));
/*     */   }
/*     */   
/*     */   public synchronized void close() throws IOException
/*     */   {
/* 127 */     if (this.in != null) {
/* 128 */       this.in.close();
/*     */     }
/*     */   }
/*     */   
/*     */   public class NewLineReader {
/*     */     private static final int DEFAULT_BUFFER_SIZE = 65536;
/* 134 */     private int bufferSize = 65536;
/*     */     private InputStream in;
/*     */     private byte[] buffer;
/* 137 */     private int bufferLength = 0;
/* 138 */     private int bufferPosn = 0;
/*     */     
/*     */     public NewLineReader(InputStream in) {
/* 141 */       this(in, 65536);
/*     */     }
/*     */     
/*     */     public NewLineReader(InputStream in, int bufferSize) {
/* 145 */       this.in = in;
/* 146 */       this.bufferSize = bufferSize;
/* 147 */       this.buffer = new byte[this.bufferSize];
/*     */     }
/*     */     
/*     */     public NewLineReader(InputStream in, Configuration conf) throws IOException {
/* 151 */       this(in, conf.getInt("io.file.buffer.size", 65536));
/*     */     }
/*     */     
/*     */     public void close() throws IOException {
/* 155 */       this.in.close();
/*     */     }
/*     */     
/*     */     public int readLine(Text str, int maxLineLength, int maxBytesToConsume) throws IOException {
/* 159 */       str.clear();
/* 160 */       Text record = new Text();
/* 161 */       int txtLength = 0;
/* 162 */       long bytesConsumed = 0L;
/* 163 */       boolean newline = false;
/* 164 */       int sepPosn = 0;
/*     */       do
/*     */       {
/* 167 */         if (this.bufferPosn >= this.bufferLength) {
/* 168 */           this.bufferPosn = 0;
/* 169 */           this.bufferLength = this.in.read(this.buffer);
/*     */           
/* 171 */           if (this.bufferLength <= 0) {
/*     */             break;
/*     */           }
/*     */         }
/* 175 */         int startPosn = this.bufferPosn;
/* 176 */         for (; this.bufferPosn < this.bufferLength; this.bufferPosn += 1)
/*     */         {
/* 178 */           if ((sepPosn > 0) && (this.buffer[this.bufferPosn] != TrackRecordReader.this.separator[sepPosn])) {
/* 179 */             sepPosn = 0;
/*     */           }
/*     */           
/* 182 */           if (this.buffer[this.bufferPosn] == TrackRecordReader.this.separator[sepPosn]) {
/* 183 */             this.bufferPosn += 1;
/* 184 */             int i = 0;
/*     */             
/* 186 */             for (sepPosn++; sepPosn < TrackRecordReader.this.separator.length; sepPosn++)
/*     */             {
/* 188 */               if (this.bufferPosn + i >= this.bufferLength) {
/* 189 */                 this.bufferPosn += i - 1;
/* 190 */                 break;
/*     */               }
/*     */               
/* 193 */               if (this.buffer[(this.bufferPosn + i)] != TrackRecordReader.this.separator[sepPosn]) {
/* 194 */                 sepPosn = 0;
/* 195 */                 break;
/*     */               }
/* 186 */               i++;
/*     */             }
/*     */             
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 199 */             if (sepPosn == TrackRecordReader.this.separator.length) {
/* 200 */               this.bufferPosn += i;
/* 201 */               newline = true;
/* 202 */               sepPosn = 0;
/* 203 */               break;
/*     */             }
/*     */           }
/*     */         }
/* 207 */         int readLength = this.bufferPosn - startPosn;
/* 208 */         bytesConsumed += readLength;
/*     */         
/* 210 */         if (readLength > maxLineLength - txtLength) {
/* 211 */           readLength = maxLineLength - txtLength;
/*     */         }
/* 213 */         if (readLength > 0) {
/* 214 */           record.append(this.buffer, startPosn, readLength);
/* 215 */           txtLength += readLength;
/*     */           
/* 217 */           if (newline) {
/* 218 */             str.set(record.getBytes(), 0, record.getLength() - TrackRecordReader.this.separator.length);
/*     */           }
/*     */         }
/* 221 */       } while ((!newline) && (bytesConsumed < maxBytesToConsume));
/* 222 */       if (bytesConsumed > 2147483647L) {
/* 223 */         throw new IOException("Too many bytes before newline: " + bytesConsumed);
/*     */       }
/*     */       
/* 226 */       return (int)bytesConsumed;
/*     */     }
/*     */     
/*     */     public int readLine(Text str, int maxLineLength) throws IOException {
/* 230 */       return readLine(str, maxLineLength, Integer.MAX_VALUE);
/*     */     }
/*     */     
/*     */     public int readLine(Text str) throws IOException {
/* 234 */       return readLine(str, Integer.MAX_VALUE, Integer.MAX_VALUE);
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Users\zhaoxiang\Desktop\basestat_log_common_tools-0.3.jar!\com\bj58\analysis\track\format\TrackRecordReader.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       0.7.1
 */